﻿using System;
using System.Data;
using ContractManager.BLL.Business;
using ContractManager.Common.Class;
using ContractManager.Common.FormBase;

namespace ContractManager.Reports.TendersDocuments
{
    public partial class FrmTenderDocumentDetails : XtraFormBase
    {
        #region "Form Construction"
        public FrmTenderDocumentDetails()
        {
            InitializeComponent();
        }
        #endregion

        #region "Private Method"

        private void DoPerform()
        {
            DataTable dataTable = ClsReports.GetTenderDocumentDetails(txtFromDate.DateTime, txtToDate.DateTime);
            grdReport.DataSource = dataTable;

        }

        private void DoPrint()
        {
            string fileName = ReportName;
            string reportName = ClsVariable.GetReportFullPath(fileName);
            
            var report = new Stimulsoft.Report.StiReport();
            report.Load(reportName);

            ClsVariable.CreateWaitDialog(ClsVariable.StrCaption, "Vui lòng đợi...");
            ClsVariable.SetWaitDialogCaption("Đang nạp dữ liệu báo cáo...");

            DataTable dtReport = ClsReports.GetTenderDocumentDetails(txtFromDate.DateTime, txtToDate.DateTime);
            report.RegData(dtReport);
            report.Compile();
            ClsVariable.CloseWaitDialog();
            // In thông tin đơn vị, địa chỉ

            report["KyBaoCao"] = String.Format("Từ ngày {0} Đến ngày {1}", txtFromDate.DateTime.ToString("dd/MM/yyyy"),
                                               txtToDate.DateTime.ToString("dd/MM/yyyy"));

           
            ClsVariable.ApplyReportParam(report, ClsVariable.DtParam);
            report.Render(true);
            report.Show(this.MdiParent);
        }
        #endregion

        #region "Button Event"
        private void btnOk_Click(object sender, EventArgs e)
        {
            DoPerform();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            DoPrint();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }
        #endregion

        private void FrmTenderDocumentDetails_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(FormReportLayoutTemplate))
            {
                string filePath = ClsVariable.GetRestoreLayoutFullPath(FormReportLayoutTemplate);
                grvReport.RestoreLayoutFromXml(filePath, DevExpress.Utils.OptionsLayoutBase.FullLayout);
            }
        }

        

    }
}
